// 获取视频信息 - API
async function getVideoInfo(bvid) {
  const response = await fetch(
    `https://api.bilibili.com/x/web-interface/view?bvid=${bvid}&jsonp=jsonp`
  );
  if (!response.ok) {
    throw new Error("水真汽助手 - Network response was not ok");
  }
  const { data } = await response.json();
  let vtype = 1; // 1: 单个视频; 2: 分集视频; 3: 合集视频
  if (data.pages.length > 1) {
    vtype = 2;
  } else if (data.ugc_season) {
    vtype = 3;
  }
  return { vtype, data };
}
//发送评论申诉
async function submitAppeal(messagePayload) {
  let formData = new FormData();
  if ("bvid" in messagePayload) {
    formData.append("oid", messagePayload.bvid);
  }
  if ("url" in messagePayload) {
    formData.append("url", messagePayload.url);
  }
  formData.append("csrf", messagePayload.csrf);
  formData.append("type", "1");
  formData.append("reason", messagePayload.reason);
  const response = await fetch(
    `https://api.bilibili.com/x/v2/reply/appeal/submit`,
    {
      method: "POST",
      credentials: "include",
      // headers: {
      //   "Content-Type": "application/x-www-form-urlencoded",
      // },
      body: formData,
    }
  );
  if (!response.ok) {
    throw new Error("水真汽助手 - appeal response was not ok");
  }
  const { code, data, message } = await response.json();

  return { code, data, message };
}
